mui.init({
	swipeBack: false //启用右滑关闭功能  
});
mui.plusReady(function() {
	var self = plus.webview.currentWebview();
	order_detail = new Vue({
		el: '#confirm_order',
		data: {
			'courseId': '',
			'title': '',
			'largePicture': '',
			'price': '',
			'cus_list': '',
			'pay_methods': 'wxpay',
			'address': '',
			'custom_id': '',
			'consultant_name': '',
		},

		mounted() {
			this.get_data();
		},

		methods: {
			get_data: function() {
				this.courseId = self.courseId;
				this.title = self.title;
				this.largePicture = self.largePicture;
				this.price = self.price;
				/*查询当前用户是否已经有专属客服*/
				var api_host = plus.storage.getItem('HOST_URL');

				mui.ajax({
					url: api_host + '/api/cusservice/cusservice/getMemberCustomer',
					dataType: 'json',
					headers: {
						'User-Token': plus.storage.getItem('UserToken')
					},
					type: 'get',
					success: function(msg) {
						order_detail.consultant_name = msg.data.name;
					},
					error: function() {
						console.log('获取当前会员的专属客服失败');
					}
				})

			},
			
			choose_consultant: function() {
				var api_host = plus.storage.getItem('HOST_URL');

				mui.ajax({
					url: api_host + '/api/cusservice/cusservice/cuslist',
					dataType: 'json',
					headers: {
						'User-Token': plus.storage.getItem('UserToken')
					},
					type: 'get',
					success: function(msg) {
						if (msg.code == 1) {
							order_detail.cus_list = msg.data;
							$('.popMask').show();
							$('.popConsultant').animate({
								'bottom': '0%'
							}, 300).show();
						} else {
							mui.toast(msg.msg, {
								duration: '200',
								type: 'div'
							});
						}
					},
					error: function() {
						console.log('获取客服列表失败');
					},
					complete: function() {
						plus.nativeUI.closeWaiting();
					}
				})
			},

			confirm_custome: function(custom_id, name) {
				var api_host = plus.storage.getItem('HOST_URL');
				order_detail.consultant_name = name;

				mui.ajax({
					url: api_host + '/api/cusservice/cusservice/addMemberCustomer',
					dataType: 'json',
					data: {
						'custom_id': custom_id,
						'name': name
					},
					headers: {
						'User-Token': plus.storage.getItem('UserToken')
					},
					type: 'post',
					async: true,
					timeout: 3000,
					success: function(data) {
						mui.toast(data.msg, {
							duration: '1000'
						});
						$('.popMask').hide();
						$('.popConsultant').animate({
							'bottom': '-100%'
						}, 300).hide(300);
					},
					error: function(xhr, type, errorThrown) {
						console.log('系统错误');
					},
					complete: function() {
						plus.nativeUI.closeWaiting();
					}
				});
			},

			close_consultant: function() {
				$('.popMask').hide();
				$('.popConsultant').animate({
					'bottom': '-100%'
				}, 300).hide(300).stop(true, true);
				$('.popPay').animate({
					'bottom': '-100%'
				}, 300).hide(300).stop(true, true);
			},
			
			choose_li: function(e) {
				this.custom_id = e.target.getAttribute('custome-id');
				this.consultant_name = e.target.getAttribute('name');
				console.log(e);
			},
			
			addAddress: function() {
				$('.popMask').show();
				$('.popAddress').animate({
					'bottom': '0%'
				}, 300).show();
			},

			subOrder: function() {
				$('.popMask').show();
				$('.popPay').animate({
					'bottom': '0%'
				}, 300).show();
			},
			
			closePay: function() {
				$('.popMask').hide();
				$('.popPay').animate({
					'bottom': '-100%'
				}, 300).hide(300).stop(true, true);
			},

			pay_way: function(e) {
				this.pay_methods = e;
			},

			comfirmPay: function(payway) {
				var goodsInfo = {
					'id': order_detail.courseId,
					'price': this.price,
				};
				new pay().start('course', payway, 1, goodsInfo);
			}
		}
	})
});

//解决tap点透
$(function() {
	FastClick.attach(document.body);
});
